﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using uzing;

namespace example_tcp_server
{
    class Program
    {
        static void Main(string[] args)
        {
            uzCTcpServer server = new uzCTcpServer();
            CTcpClientSync client = null;
            server.OpenServer(9000);
            int dataSize = 1024;
            byte[] buffer = new byte[dataSize];
            ASCIIEncoding encoder = new ASCIIEncoding();

            while (true)
            {
                if (null == client)
                {
                    client = server.CheckForNewConnection(UZING_TCP.NON_BLOCKING);
                    System.Console.WriteLine("No Connection");
                }
                else
                {
                    int recvSize = client.Receive(buffer, 0, dataSize, UZING_TCP.NON_BLOCKING);
                    if (recvSize == dataSize)
                    {
                        System.Console.WriteLine(encoder.GetString(buffer));
                    }
                    else
                    {
                        //System.Console.WriteLine("No Data");
                    }
                }

                System.Threading.Thread.Sleep(10);
            }
        }
    }
}
